<?php 
require_once("../inc/config.inc.php");
function timeDifferenceNotes($c_id) {

	$sql = "SELECT UNIX_TIMESTAMP() - UNIX_TIMESTAMP(date) FROM notes WHERE notes.c_id='$c_id'";
	$res = mysql_query($sql) or die(mysql_error());
	$seconds = mysql_result($res,0,0);
	//echo 'Seconds from query:' . $seconds;
	//echo $sql;
	
    if ($seconds < 60) return "$seconds seconds ago";
    $minutes = floor($seconds/60);
    if ($minutes < 2) return "1 minute ago";
    if ($minutes < 60) return "$minutes minutes ago";
    $hours = floor($seconds/3600);
    if ($hours < 2) return "1 hour ago";
    if ($hours < 24) return "$hours hours ago";
    $days = floor($seconds/3600/24);
    if ($days < 2) return "yesterday";
    return "$days days ago";
}
function timeDifferenceStatus($c_id) {

	$sql = "SELECT UNIX_TIMESTAMP() - UNIX_TIMESTAMP(updated) FROM status WHERE status.c_id='$c_id'";
	$res = mysql_query($sql) or die(mysql_error());
	$seconds = mysql_result($res,0,0);
	//echo 'Seconds from query:' . $seconds;
	//echo $sql;
	
    if ($seconds < 60) return "$seconds seconds ago";
    $minutes = floor($seconds/60);
    if ($minutes < 2) return "1 minute ago";
    if ($minutes < 60) return "$minutes minutes ago";
    $hours = floor($seconds/3600);
    if ($hours < 2) return "1 hour ago";
    if ($hours < 24) return "$hours hours ago";
    $days = floor($seconds/3600/24);
    if ($days < 2) return "yesterday";
    return "$days days ago";
}
function timeDifferenceLatestProjects($p_id) {

	$sql = "SELECT UNIX_TIMESTAMP() - UNIX_TIMESTAMP(date_started) FROM projects WHERE projects.p_id='$p_id'";
	$res = mysql_query($sql) or die(mysql_error());
	$seconds = mysql_result($res,0,0);
	
    if ($seconds < 60) return "$seconds seconds ago";
    $minutes = floor($seconds/60);
    if ($minutes < 2) return "1 minute ago";
    if ($minutes < 60) return "$minutes minutes ago";
    $hours = floor($seconds/3600);
    if ($hours < 2) return "1 hour ago";
    if ($hours < 24) return "$hours hours ago";
    $days = floor($seconds/3600/24);
    if ($days < 2) return "yesterday";
    return "$days days ago";
}
?>
